//用户信息 
function user_infoHandle(data) { 
	$("#mag").val(data.msg); //提示
	$("#name").val(data.data.nickname); //昵称
}

/*
 **首页界面
 */
//动态列表处理
/*function recommendHandle(data,img) {
	console.log(JSON.stringify(data));
	if(data.error_code == 10007) {
		var html = '<div class="not_logged_in">' +
			'<img src="../../images/wdl.png">' +
			'<p>登录后发现你关注人的动态哦~</p>' +
			'<div id="login">' +
			'	<a href="#" >登录</a>/<a href="#">注册</a>' +
			'</div>' +
			'</div>';
		$(".mui-content").html(html);
	} else { 
		var isOver = $("#isOver").val();  
		var number = $("#number").val(); //页数
		var p = data.data.totalElements/5; //總頁數 
			console.log("总页数"+p);
			console.log("加载第"+$("#number").val()+"页")
			if(number+1 > p) { //当前的页数
				console.log("11");
				$("#isOver").val(true); 
				mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
			}
			if(number+1== p) { //当前的页数
				console.log("22")
				$("#isOver").val(true); 
				mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
			} 
			if(isOver == "false") { 
				var ye= Number(number) + Number(1);
				$("#number").val(ye++);
				console.log("第"+$("#number").val()+"页")
				mui('#refreshContainer').pullRefresh().endPullupToRefresh(true); //停止正在加载
				mui('#refreshContainer').pullRefresh().enablePullupToRefresh(); //显示上拉加载文字
			}
			
		if(!data.data || data.data.content == "") {
			var vi = $("#video").val();
			if(img == 2 || vi == "vi") { //关注人动态
				$(".mui-content").html('<div class="not_logged_in">' +
					' <img src="../../images/wdl.png">' +
					' <p>暂无动态哦~</p></div>');
			} else {
				$(".mui-content").html('<div class="not_logged_in">' +
					' <img src="images/wdl.png">' +
					' <p>暂无动态哦~</p></div>');
			}

		} else {
			
			var html = "";
			for(var i = 0; i < data.data.content.length; i++) {
				var dynamic_type = data.data.content[i].dynamic_type; //发布类型

				var arr_img = data.data.content[i].dynamic_file; //图片数组
				var img_arr = arr_img.split(","); //图片
				var is_valid = data.data.content[i].is_valid //点赞
				//var video = data.data.content[5].dynamic_file.replace(",",""); //视频 
				html += '<li class="recommend_list" id="' + data.data.content[i].dynamic_id + '">' +
					'<div class="recommend_top">' +
					'<img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].head_img_url + '">' +
					'<div class="user_info">' +
					'<p class="nickname" id="' + data.data.content[i].publisher + '">' + data.data.content[i].nickname + '</p>' + //动态用户id   头像
					'<p class="time">' + data.data.content[i].release_time + '</p>' +
					'</div>' +
					'</div>';
				if(dynamic_type == 1) { //视频
					html += '<div class="recommend_content">' +
						'<video controls="controls" name="media" width="100%" heigh="120px" >' +
						'<source src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].dynamic_file + '"/>' +
						'</video>' +
						'<p class="content_text">' + data.data.content[i].content + ' </p>' +
						'</div>';
				} else if(dynamic_type == 2) { //图片
					html += '<div class="recommend_content">' +
						'<p class="content_text">' + data.data.content[i].content + '</p>' +
						'<div class="mui-row list_img"> ';
					for(var j = 0; j < img_arr.length; j++) { //循环图片
						if(img_arr.length == 1) {
							html += '<div class="mui-col-xs-8"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + i + '1"/></div>';
						} else if(img_arr.length == 2 || img_arr.length == 4) {
							html += '<div class="mui-col-xs-6"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + i + '1"/></div>';
						} else if(img_arr.length = 3) {
							html += '<div class="mui-col-xs-4"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + i + '1"/></div>';
						} else if(img_arr.length > 4) {
							html += '<div class="mui-col-xs-4"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + i + '1"/></div>';
						}
					}
					html += '</div>' +
						'</div>';
				}
				html += '<div class="recommend_operation">' +
					'<div class="zan">';
				if(is_valid == 1) {
					html += '<span><em class="iconfont icon-xihuan lover"></em><em>' + data.data.content[i].praise + '</em></span>';
				} else {
					html += '<span><em class="iconfont icon-xihuan"></em><em>' + data.data.content[i].praise + '</em></span>';
				}
				html += '</div>' +
					'<div class="comment">' +
					'<span><em class="iconfont icon-comment"></em><em>' + data.data.content[i].comment_number + '</em></span>' +
					'</div>' +
					'<div class="more" >' +
					'<a href="#sheet"><em class="iconfont icon-gengduo"></em></a>' +
					'</div>' +
					'</div>' +
					'</li>';

			}
			$("#commList").append(html);

			//图片大小处理
			var width4 = $(".list_img .mui-col-xs-4").width();
			$(".list_img .mui-col-xs-4").height(width4);
			var width6 = $(".list_img .mui-col-xs-6").width();
			$(".list_img .mui-col-xs-6").height(width6);
		} 
	}
}*/

//无页数处理方式
//动态数据处理 
function recommendHandle(data, img) { 
	if(data.error_code == 10007) {
		var html = '<div class="not_logged_in">' +
			'<img src="../../images/wdl.png">' +
			'<p>登录后发现你关注人的动态哦~</p>' +
			'<div id="login">' +
			'	<a href="#" >登录</a>/<a href="#">注册</a>' +
			'</div>' +
			'</div>';
		$(".mui-content").html(html);
	} else {
		var number = $("#number").val(); //页数
		if(number == 0) {
			if(!data.data || data.data.content == "") {
				var vi = $("#video").val();
				if(img == 2 || vi == "vi") { //关注人动态
					$(".mui-content").html('<div class="not_logged_in">' +
						' <img src="../../images/wdl.png">' +
						' <p>暂无动态哦~</p></div>');
				} else {
					$(".mui-content").html('<div class="not_logged_in">' +
						' <img src="images/wdl.png">' +
						' <p>暂无动态哦~</p></div>');
				}

			} else {
				dynamic_data(data);
			}

		} else {
			if(!data.data || data.data.content == "") {
				$("#isOver").val(true);
				mui('#refreshContainer').pullRefresh().endPullupToRefresh(true); //停止正在加载
			} else {
				dynamic_data(data);
			}
		}

	}
}

//动态数据处理
function dynamic_data(data) {
	var number = $("#number").val(); //页数
	var isOver = $("#isOver").val();
	var title=$("title").text(); 
	if(isOver == "false") {
		var ye = Number(number) + Number(1);
		$("#number").val(ye++);
		mui('#refreshContainer').pullRefresh().endPullupToRefresh(true); //停止正在加载
		mui('#refreshContainer').pullRefresh().enablePullupToRefresh(); //显示上拉加载文字
	} else {
		//isOver = true;
		$("#isOver").val(true);
		mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
	}
	var html = "";
	for(var i = 0; i < data.data.content.length; i++) {
		var dynamic_type = data.data.content[i].dynamic_type; //发布类型

		var arr_img = data.data.content[i].dynamic_file; //图片数组
		var img_arr = arr_img.split(","); //图片
		var is_valid = data.data.content[i].is_valid //点赞
		//var video = data.data.content[5].dynamic_file.replace(",",""); //视频  
		var head_img_url = data.data.content[i].head_img_url; 
		html += '<li class="recommend_list" id="' + data.data.content[i].dynamic_id + '">' +
			'<div class="recommend_top">' ;
			if(!head_img_url){
				if(title=="推荐"){
					html+='<img src="images/log.png">';
				}else{
					html+='<img src="../../images/log.png">';
				}
			}else{
				html+='<img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].head_img_url + '">' ;
			} 
		html+='<div class="user_info">' +
			'<p class="nickname" id="' + data.data.content[i].publisher + '">' + data.data.content[i].nickname + '</p>' + //动态用户id   头像
			'<p class="time">' + data.data.content[i].release_time + '</p>' +
			'</div>' +
			'</div>';
		if(dynamic_type == 1) { //视频 
			html += '<div class="recommend_content">' +
				'<p class="content_text">' + data.data.content[i].content + ' </p>' +
				'<div class="video_center" >'+ 
				'<video name="media" width="100%"  height="220px"   poster="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].dynamic_file + '?spm=a2c4g.11186623.2.1.yjOb8V&x-oss-process=video/snapshot,t_1000,m_fast">' +   //  视频封面
				'<source src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].dynamic_file + '"/>' +
				'</video>' ;
				if(title=="推荐"){
					html+='<div class="img_video"><img src="images/ship.png" width="20%"></div></div>';
				}else{
					html+='<div class="img_video"><img src="../../images/ship.png" width="20%"></div></div>';
				} 
		
			html += '</div>'; 
		} else if(dynamic_type == 2) { //图片
			html += '<div class="recommend_content">' +
				'<p class="content_text">' + data.data.content[i].content + '</p>' +
				'<div class="mui-row list_img"> ';
			if(arr_img != "") {
				for(var j = 0; j < img_arr.length; j++) { //循环图片
					if(img_arr.length == 1) {
						html += '<div class="mui-col-xs-8"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + data.data.content[i].dynamic_id + '1"/></div>';
					} else if(img_arr.length == 2 || img_arr.length == 4) {
						html += '<div class="mui-col-xs-6"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + data.data.content[i].dynamic_id + '1"/></div>';
					} else if(img_arr.length = 3) {
						html += '<div class="mui-col-xs-4"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + data.data.content[i].dynamic_id + '1"/></div>';
					} else if(img_arr.length > 4) {
						html += '<div class="mui-col-xs-4"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="' + data.data.content[i].dynamic_id + '1"/></div>';
					}
				}
			}

			html += '</div>' +
				'</div>';
		}
		html += '<div class="recommend_operation">' +
			'<div class="zan">';
		if(is_valid == 1) {
			html += '<span><em class="iconfont icon-xihuan lover"></em><em>' + data.data.content[i].praise + '</em></span>';
		} else {
			html += '<span><em class="iconfont icon-xihuan"></em><em>' + data.data.content[i].praise + '</em></span>';
		}
		html += '</div>' +
			'<div class="comment">' +
			'<span><em class="iconfont icon-comment"></em><em>' + data.data.content[i].comment_number + '</em></span>' +
			'</div>' +
			'<div class="more" >' +
			'<a href="#sheet"><em class="iconfont icon-gengduo"></em></a>' +
			'</div>' +
			'</div>' +
			'</li>';

	}
	$("#commList").append(html);

	//图片大小处理
	var width4 = $(".list_img .mui-col-xs-4").width();
	$(".list_img .mui-col-xs-4").height(width4);
	var width6 = $(".list_img .mui-col-xs-6").width();
	$(".list_img .mui-col-xs-6").height(width6);
}

// 处理首页推荐点赞方法 
/*function dynamic_labelHandle(data) {
	console.log(JSON.stringify(data));
	console.log($("#zan").val())
	if(data.error_code == 10000) {  
		$("#zan").val(data.error_code);
	} else { 
		$("#zan").val(data.error_code);
		//mui.toast("该条动态已赞");  
	}
}*/

//首页关注列表
function buddy_dynamicsHandle(data) {
	var img = 2;
	recommendHandle(data, img);
}

/*
 **图文详情界面
 */
//动态详情 
function find_dynamic_by_idHandle(data) { 
	$(".details_image").attr("id", data.data.publisher); //用户id
	var head_img_url=data.data.head_img_url;
	if(!head_img_url){
		$(".details_image .details_image_img img").attr("src", "../../images/log.png"); //头像 
	}else{
		$(".details_image .details_image_img img").attr("src", "https://ypao.oss-cn-shenzhen.aliyuncs.com/" + data.data.head_img_url); //头像
	} 	
	$(".details_image .details_image_name").text(data.data.nickname); //昵称
	$(".details_image .time").text(data.data.release_time); //发布时间
	var is_valid = data.data.is_valid; //关注用户
	if(is_valid == 1) {
		$(".follow").text("已关注");
	} else {
		$(".follow").text("+ 关注");
	}
	$(".details_text").text(data.data.content); //发布内容
	var dynamic_type = data.data.dynamic_type; //动态类型
	$("#dynamic_type").val(dynamic_type); //动态类型赋值
	var arr_img = data.data.dynamic_file; //图片数组
	var img_arr = arr_img.split(","); //图片 
	var html = "";
	//console.log(img_arr.length);
	if(dynamic_type == 2) { //图片
		html += '<div class="mui-row list_img"> ';
		for(var j = 0; j < img_arr.length; j++) { //循环图片
			if(img_arr.length == 1) {
				html += '<div class="mui-col-xs-12"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="1"/></div>';
			} else if(img_arr.length == 2 || img_arr.length == 4) {
				html += '<div class="mui-col-xs-6"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="1"/></div>';
			} else if(img_arr.length = 3) {
				html += '<div class="mui-col-xs-4"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="1"/></div>';
			} else if(img_arr.length > 4) {
				html += '<div class="mui-col-xs-4"><img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + img_arr[j] + '" data-preview-src="" data-preview-group="1"/></div>';
			}
		}
		html += '</div> ';
	} else if(dynamic_type == 1) { //视频
		html += '<video name="media" width="100%" heigh="120px" controls="controls" poster="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.dynamic_file + '?spm=a2c4g.11186623.2.1.yjOb8V&x-oss-process=video/snapshot,t_1000,m_fast" >' +
			'<source src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.dynamic_file + '"/>' +
			'</video>';
	}
	$(".details_picture").html(html);
	var is_valid2 = data.data.is_valid2; //点赞
	if(is_valid2 == 1) {
		$(".all_publish_icon").addClass("all_icon_color");
	}
	$(".details_comment").text("评论" + data.data.comment_number); //评论数量  
	$(".zan").text(data.data.praise); //赞
	$(".pinglun").text(data.data.comment_number); //评论

	//判断用户关注 
	if(data.data.publisher == user_id) {

	} else {
		$(".follow").css("display", "block");
	}

	//图片大小处理
	var width4 = $(".list_img .mui-col-xs-4").width();
	$(".list_img .mui-col-xs-4").height(width4);
	var width6 = $(".list_img .mui-col-xs-6").width();
	$(".list_img .mui-col-xs-6").height(width6);
}

//评论列表
function dynamic_reviewHandle(data) { 
	if(data.error_code == 10001) {
		mui.toast(data.msg)
	} else if(data.data == "" || data.data.content.length == 0 || data.data.content == "") {
		$(".conment_all").html('<p class="text_unll">快来发表你的评论吧</p>');
		$(".conment_all").css("margin-bottom","60px");
	} else {
		var html = "";
		for(var i = 0; i < data.data.content.length; i++) {
			var id = data.data.content[i].user_id; //互动id
			var comment_type = data.data.content[i].comment_type; //评论类型
			var head_img_url=data.data.content[i].head_img_url;
			html += '<li class="mui-table-view-cell details_comment_list" sta="' + data.data.content[i].comment_id + '" id="' + data.data.content[i].user_id + '">' +
				'<div class="details_comment_img">' ;
			if(!head_img_url){
				html += '<img width="100%" src="../../images/log.png" />';
			}else{
				html += '<img width="100%" src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data.content[i].head_img_url + ' " />';
			}
			html += '</div>' +
				'<div class="details_comment_right">' +
				'<span class="details_comment_name">' + data.data.content[i].nickname + '</span>' +
				'<p class="details_comment_text">' + data.data.content[i].content + '</p>';
			if(comment_type == 2) {
				html += '<div class="comment_con_list">' +
					'<p>回复' + data.data.content[i].username + '：' + data.data.content[i].parent_content + '</p>' +
					'</div>'
			}
			html += '<p class="details_comment_time">' + data.data.content[i].create_time + '</p>' +
				'</div>' +
				'</li>';
		}
		$(".conment_all").append(html);
		$(".more_comment").css("display","block");
	}
}

//发送评论
function comment_dynamicsHandle(data) { 
	if(data.error_code == 10000) {
		location.reload(); //去掉该元素 刷新  
	} else {
		mui.toast("评论失败");
	} 
}

//关注用户
function concernHandle(data) { 
	if(data.error_code == 10000) {
		var text = $(".follow").text();
		if(text == "已关注") {
			$(".follow").text("+ 关注");
			mui.toast("取消关注成功");
		} else {
			$(".follow").text("已关注");
			mui.toast("关注成功");
		}
	} else {

	}
}

/*
 **发布
 */
//发布动态
function release_dynamicHandle(data) { 
	if(data.error_code == 10000) {
		mui.toast("发布成功");
		window.top.location.href = "../../Recommend.html";
	} else if(data.error_code == 10007) {
		mui.toast(data.msg);
	}
}

/*
举报*/
function accusationHandle(data) { 
	if(data.error_code == 10000) {
		mui.toast("已举报，受理中");
		mui.back();
	} else if(data.error_code == 10001) {
		mui.toast(data.msg);
	}
}

/*用户信息*/
function find_user_infoHandle(data) { 
	var head_img_url = data.data.head_img_url;
	if(!head_img_url){
		$(".fan_pages_head img").attr("src", "../../images/log.png"); //头像 
	}else{
		$(".fan_pages_head img").attr("src", "https://ypao.oss-cn-shenzhen.aliyuncs.com/" + data.data.head_img_url); //头像 
	} 
	$(".follow").attr("id", data.data.user_id); //用户id
	$(".fan_pages_head .mui-media-body").text(data.data.nickname) //昵称
	$("#follow").text(data.data.follow) //关注
	$("#fans").text(data.data.fans); //粉丝
	$("#marked").text(data.data.marked); //标记 
	//是否关注
	var is_valid = data.data.is_valid;
	if(is_valid == 1) {
		$(".follow").text("已关注");
	} else {
		$(".follow").html('+关注');
	}

	//判断用户关注 
	if(data.data.user_id == user_id) {

	} else {
		$(".mui-bar").css("display", "block");
	}

}

//荣誉值
function _honor_valueHandle(data) { 
	var value_number = Number(data.data)
	$('#rongyu').text(value_number.toFixed(4)); //个性签名
}